package com.globalwave.util
{
	import mx.controls.Alert;
	
	public class Convertor
	{
		public static function transfer (fromObj :Object,toObj:Object) :void {
		    for (var pro :String in fromObj) {
		    	toObj[pro] = fromObj[pro] ;
		    }
		}
		
		public static function object2Form(obj :Object,formObj:Object) :void {
			for (var pro :String in obj) {	
				try {		
					if (formObj[pro].className == "CheckBox") {
						formObj[pro].selected = Boolean(obj[pro]) ;
					} else if (formObj[pro].className == "TextInput"){
						formObj[pro].text = obj[pro] ;
					} else if (formObj[pro].className == "RichTextEditor" ){
						formObj[pro].htmlText = obj[pro] ;
					} else if (formObj[pro].className == "NumericStepper") {
					    formObj[pro].value = obj[pro]; ;
				    }
		    	    
				}catch(e:Error) {
					
				}
		   }
		}
		
		public static function form2Object(formObj:Object,obj :Object) :void {
			
						//Alert.show( ":" ) ;
			for (var pro :String in obj) {	
				try {		
						Alert.show(pro + ":" ) ;
					if (formObj[pro].className == "CheckBox") {
						obj[pro] = formObj[pro].selected ;
					} else if (formObj[pro].className == "TextInput"){
						Alert.show(pro + ":" + formObj[pro].text) ;
						obj[pro] = formObj[pro].text ;
					} else if (formObj[pro].className == "RichTextEditor" ){
						obj[pro] = formObj[pro].htmlText ;
					} else if (formObj[pro].className == "NumericStepper") {
					    obj[pro] = formObj[pro].value; ;
				    }
		    	    
				}catch(e:Error) {
					
				}
		   }
		}
		
		public static function escapedParam(src : String) : String  {
		    return src.split("&").join("&amp;").split( "<").join("&lt;") ;
		}
		/*
		public static function form2object(formObj:Form,obj :Object) :void {

            for (var i:int = 0; i < formObj.getChildren().length ; i++) {
                var formItem:Object = formObj.getChildren()[i];
                

                
                for(var j:int = 0; j < formItem.getChildren().length ; j++) {
                    var elem : Object = formItem.getChildren()[j];
                    try {
	                    if ( elem.className == "CheckBox") {
							if (elem.selected) {
							    obj[elem.id] = "true" ;	
							} else {
							    obj[elem.id] = "false" ;
							}	               
	                    } else if (elem.className == "TextInput"){
							obj[elem.id] = elem.text ;	
						} else if (elem.className == "RichTextEditor"){
							obj[elem.id] = elem.htmlText.replace(/</g,"&gl;") ;
							Alert.show(obj[elem.id]) ;
							//obj[elem.id] = elem.text ;	
						} else if (elem.className == "NumericStepper") {
							obj[elem.id] = elem.value ; ;
						}
	                } catch(e:Error) {
                        Alert.show("[form2object]" + e.name) ;
	                }
                }
		   }
		}*/
	}
}